/* number of 'in use' pfns in the guest (i.e. #P2M entries with a valid mfn) */
static unsigned long nr_pfns;
-static ssize_t
-read_exact(int fd, void *buf, size_t count)
-{
- int r = 0, s;
- unsigned char *b = buf;
-
- while (r < count) {
- s = read(fd, &b[r], count - r);
- if ((s == -1) && (errno == EINTR))
- continue;
- if (s <= 0) {
- break;
- }
- r += s;
- }
-
- return (r == count) ? 1 : 0;
-}
-
static int
populate_page_if_necessary(int xc_handle, uint32_t dom, unsigned long gmfn,
struct xen_ia64_p2m_table *p2m_table)
ERROR("cannot map page");
return -1;
}
- if (!read_exact(io_fd, mem, PAGE_SIZE)) {
+ if (read_exact(io_fd, mem, PAGE_SIZE)) {
ERROR("Error when reading from state file (5)");
munmap(mem, PAGE_SIZE);
return -1;
unsigned long *pfntab = NULL;
unsigned int nr_frees;
- if (!read_exact(io_fd, &count, sizeof(count))) {
+ if (read_exact(io_fd, &count, sizeof(count))) {
ERROR("Error when reading pfn count");
goto out;
}
goto out;
}
- if (!read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) {
+ if (read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) {
ERROR("Error when reading pfntab");
goto out;
}
xc_ia64_recv_vcpu_context(int xc_handle, int io_fd, uint32_t dom,
uint32_t vcpu, vcpu_guest_context_t *ctxt)
{
- if (!read_exact(io_fd, ctxt, sizeof(*ctxt))) {
+ if (read_exact(io_fd, ctxt, sizeof(*ctxt))) {
ERROR("Error when reading ctxt");
return -1;
}
return -1;
}
- if (!read_exact(io_fd, shared_info, PAGE_SIZE)) {
+ if (read_exact(io_fd, shared_info, PAGE_SIZE)) {
ERROR("Error when reading shared_info page");
munmap(shared_info, PAGE_SIZE);
return -1;
ERROR("Could not get domain info");
goto out;
}
- if (!read_exact(io_fd, &max_virt_cpus, sizeof(max_virt_cpus))) {
+ if (read_exact(io_fd, &max_virt_cpus, sizeof(max_virt_cpus))) {
ERROR("error reading max_virt_cpus");
goto out;
}
goto out;
}
memset(vcpumap, 0, vcpumap_size);
- if (!read_exact(io_fd, vcpumap, vcpumap_size)) {
+ if (read_exact(io_fd, vcpumap, vcpumap_size)) {
ERROR("read vcpumap");
goto out;
}
}
/* Set HVM-specific parameters */
- if (!read_exact(io_fd, magic_pfns, sizeof(magic_pfns))) {
+ if (read_exact(io_fd, magic_pfns, sizeof(magic_pfns))) {
ERROR("error reading magic page addresses");
goto out;
}
*store_mfn = magic_pfns[0];
/* Read HVM context */
- if (!read_exact(io_fd, &rec_size, sizeof(rec_size))) {
+ if (read_exact(io_fd, &rec_size, sizeof(rec_size))) {
ERROR("error read hvm context size!\n");
goto out;
}
goto out;
}
- if (!read_exact(io_fd, hvm_buf, rec_size)) {
+ if (read_exact(io_fd, hvm_buf, rec_size)) {
ERROR("error loading the HVM context");
goto out;
}
/* For info only */
nr_pfns = 0;
- if ( !read_exact(io_fd, &p2m_size, sizeof(unsigned long)) )
+ if ( read_exact(io_fd, &p2m_size, sizeof(unsigned long)) )
{
ERROR("read: p2m_size");
goto out;
}
DPRINTF("xc_linux_restore start: p2m_size = %lx\n", p2m_size);
- if (!read_exact(io_fd, &ver, sizeof(unsigned long))) {
+ if (read_exact(io_fd, &ver, sizeof(unsigned long))) {
ERROR("Error when reading version");
goto out;
}
goto out;
}
- if (!read_exact(io_fd, &domctl.u.arch_setup, sizeof(domctl.u.arch_setup))) {
+ if (read_exact(io_fd, &domctl.u.arch_setup, sizeof(domctl.u.arch_setup))) {
ERROR("read: domain setup");
goto out;
}
unsigned long memmap_size;
xen_ia64_memmap_info_t *memmap_info;
- if (!read_exact(io_fd, &memmap_info_num_pages,
+ if (read_exact(io_fd, &memmap_info_num_pages,
sizeof(memmap_info_num_pages))) {
ERROR("read: memmap_info_num_pages");
goto out;
ERROR("Could not allocate memory for memmap_info");
goto out;
}
- if (!read_exact(io_fd, memmap_info, memmap_size)) {
+ if (read_exact(io_fd, memmap_info, memmap_size)) {
ERROR("read: memmap_info");
goto out;
}
while (1) {
unsigned long gmfn;
- if (!read_exact(io_fd, &gmfn, sizeof(unsigned long))) {
+ if (read_exact(io_fd, &gmfn, sizeof(unsigned long))) {
ERROR("Error when reading batch size");
goto out;
}
dirty_bitmap, pages, NULL, 0, stats);
}
-static inline ssize_t
-write_exact(int fd, void *buf, size_t count)
-{
- if (write(fd, buf, count) != count)
- return 0;
- return 1;
-}
-
static int
suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
int dom, xc_dominfo_t *info)
j++;
}
}
- if (!write_exact(io_fd, &j, sizeof(unsigned int))) {
+ if (write_exact(io_fd, &j, sizeof(unsigned int))) {
ERROR("Error when writing to state file (6a)");
return -1;
}
if (!xc_ia64_p2m_allocated(p2m_table, N))
pfntab[j++] = N;
if (j == sizeof(pfntab)/sizeof(pfntab[0])) {
- if (!write_exact(io_fd, &pfntab, sizeof(pfntab[0]) * j)) {
+ if (write_exact(io_fd, &pfntab, sizeof(pfntab[0]) * j)) {
ERROR("Error when writing to state file (6b)");
return -1;
}
}
}
if (j > 0) {
- if (!write_exact(io_fd, &pfntab, sizeof(pfntab[0]) * j)) {
+ if (write_exact(io_fd, &pfntab, sizeof(pfntab[0]) * j)) {
ERROR("Error when writing to state file (6c)");
return -1;
}
return -1;
}
- if (!write_exact(io_fd, ctxt, sizeof(*ctxt))) {
+ if (write_exact(io_fd, ctxt, sizeof(*ctxt))) {
ERROR("Error when writing to state file (1)");
return -1;
}
static int
xc_ia64_send_shared_info(int xc_handle, int io_fd, shared_info_t *live_shinfo)
{
- if (!write_exact(io_fd, live_shinfo, PAGE_SIZE)) {
+ if (write_exact(io_fd, live_shinfo, PAGE_SIZE)) {
ERROR("Error when writing to state file (1)");
return -1;
}
ERROR("cannot map privreg page");
return -1;
}
- if (!write_exact(io_fd, mem, PAGE_SIZE)) {
+ if (write_exact(io_fd, mem, PAGE_SIZE)) {
ERROR("Error when writing privreg to state file (5)");
munmap(mem, PAGE_SIZE);
return -1;
__set_bit(i, vcpumap);
}
- if (!write_exact(io_fd, &max_virt_cpus, sizeof(max_virt_cpus))) {
+ if (write_exact(io_fd, &max_virt_cpus, sizeof(max_virt_cpus))) {
ERROR("write max_virt_cpus");
goto out;
}
- if (!write_exact(io_fd, vcpumap, vcpumap_size)) {
+ if (write_exact(io_fd, vcpumap, vcpumap_size)) {
ERROR("write vcpumap");
goto out;
}
}
}
- if (!write_exact(io_fd, magic_pfns, sizeof(magic_pfns))) {
+ if (write_exact(io_fd, magic_pfns, sizeof(magic_pfns))) {
ERROR("Error when writing to state file (7)");
goto out;
}
goto out;
}
- if (!write_exact(io_fd, &rec_size, sizeof(rec_size))) {
+ if (write_exact(io_fd, &rec_size, sizeof(rec_size))) {
ERROR("error write hvm buffer size");
goto out;
}
- if (!write_exact(io_fd, hvm_buf, rec_size)) {
+ if (write_exact(io_fd, hvm_buf, rec_size)) {
ERROR("write HVM info failed!\n");
goto out;
}
p2m_size = xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &dom);
/* This is expected by xm restore. */
- if (!write_exact(io_fd, &p2m_size, sizeof(unsigned long))) {
+ if (write_exact(io_fd, &p2m_size, sizeof(unsigned long))) {
ERROR("write: p2m_size");
goto out;
}
{
unsigned long version = XC_IA64_SR_FORMAT_VER_CURRENT;
- if (!write_exact(io_fd, &version, sizeof(unsigned long))) {
+ if (write_exact(io_fd, &version, sizeof(unsigned long))) {
ERROR("write: version");
goto out;
}
ERROR("Could not get domain setup");
goto out;
}
- if (!write_exact(io_fd, &domctl.u.arch_setup,
+ if (write_exact(io_fd, &domctl.u.arch_setup,
sizeof(domctl.u.arch_setup))) {
ERROR("write: domain setup");
goto out;
PERROR("xc_ia64_p2m_map");
goto out;
}
- if (!write_exact(io_fd,
+ if (write_exact(io_fd,
&memmap_info_num_pages, sizeof(memmap_info_num_pages))) {
PERROR("write: arch.memmap_info_num_pages");
goto out;
}
- if (!write_exact(io_fd, memmap_info, memmap_size)) {
+ if (write_exact(io_fd, memmap_info, memmap_size)) {
PERROR("write: memmap_info");
goto out;
}
continue;
}
- if (!write_exact(io_fd, &N, sizeof(N))) {
+ if (write_exact(io_fd, &N, sizeof(N))) {
ERROR("write: p2m_size");
munmap(mem, PAGE_SIZE);
goto out;
/* terminate */
{
unsigned long pfn = INVALID_MFN;
- if (!write_exact(io_fd, &pfn, sizeof(pfn))) {
+ if (write_exact(io_fd, &pfn, sizeof(pfn))) {
ERROR("Error when writing to state file (6)");
goto out;
}
static int local_file_dump(void *args, char *buffer, unsigned int length)
{
struct dump_args *da = args;
- int bytes, offset;
- for ( offset = 0; offset < length; offset += bytes )
+ if ( write_exact(da->fd, buffer, length) == -1 )
{
- bytes = write(da->fd, &buffer[offset], length-offset);
- if ( bytes <= 0 )
- {
- PERROR("Failed to write buffer");
- return -errno;
- }
+ PERROR("Failed to write buffer");
+ return -errno;
}
- if (length >= DUMP_INCREMENT*PAGE_SIZE) {
+ if ( length >= (DUMP_INCREMENT * PAGE_SIZE) )
+ {
// Now dumping pages -- make sure we discard clean pages from
// the cache after each write
discard_file_cache(da->fd, 0 /* no flush */);
/* Address size of the guest, in bytes */
unsigned int guest_width;
-
-static ssize_t
-read_exact(int fd, void *buf, size_t count)
-{
- int r = 0, s;
- unsigned char *b = buf;
-
- while ( r < count )
- {
- s = read(fd, &b[r], count - r);
- if ( (s == -1) && (errno == EINTR) )
- continue;
- if ( s <= 0 )
- break;
- r += s;
- }
-
- return (r == count);
-}
-
/*
** In the state file (or during transfer), all page-table pages are
** converted into a 'canonical' form where references to actual mfns
xen_pfn_t p2m_fl_zero;
/* Read first entry of P2M list, or extended-info signature (~0UL). */
- if ( !read_exact(io_fd, &p2m_fl_zero, sizeof(long)) )
+ if ( read_exact(io_fd, &p2m_fl_zero, sizeof(long)) )
{
ERROR("read extended-info signature failed");
return NULL;
uint32_t tot_bytes;
/* Next 4 bytes: total size of following extended info. */
- if ( !read_exact(io_fd, &tot_bytes, sizeof(tot_bytes)) )
+ if ( read_exact(io_fd, &tot_bytes, sizeof(tot_bytes)) )
{
ERROR("read extended-info size failed");
return NULL;
char chunk_sig[4];
/* 4-character chunk signature + 4-byte remaining chunk size. */
- if ( !read_exact(io_fd, chunk_sig, sizeof(chunk_sig)) ||
- !read_exact(io_fd, &chunk_bytes, sizeof(chunk_bytes)) ||
+ if ( read_exact(io_fd, chunk_sig, sizeof(chunk_sig)) ||
+ read_exact(io_fd, &chunk_bytes, sizeof(chunk_bytes)) ||
(tot_bytes < (chunk_bytes + 8)) )
{
ERROR("read extended-info chunk signature failed");
return NULL;
}
- if ( !read_exact(io_fd, &ctxt, chunk_bytes) )
+ if ( read_exact(io_fd, &ctxt, chunk_bytes) )
{
ERROR("read extended-info vcpu context failed");
return NULL;
while ( chunk_bytes )
{
unsigned long sz = MIN(chunk_bytes, sizeof(xen_pfn_t));
- if ( !read_exact(io_fd, &p2m_fl_zero, sz) )
+ if ( read_exact(io_fd, &p2m_fl_zero, sz) )
{
ERROR("read-and-discard extended-info chunk bytes failed");
return NULL;
}
/* Now read the real first entry of P2M list. */
- if ( !read_exact(io_fd, &p2m_fl_zero, sizeof(xen_pfn_t)) )
+ if ( read_exact(io_fd, &p2m_fl_zero, sizeof(xen_pfn_t)) )
{
ERROR("read first entry of p2m_frame_list failed");
return NULL;
/* First entry has already been read. */
p2m_frame_list[0] = p2m_fl_zero;
- if ( !read_exact(io_fd, &p2m_frame_list[1],
- (P2M_FL_ENTRIES - 1) * sizeof(xen_pfn_t)) )
+ if ( read_exact(io_fd, &p2m_frame_list[1],
+ (P2M_FL_ENTRIES - 1) * sizeof(xen_pfn_t)) )
{
ERROR("read p2m_frame_list failed");
return NULL;
/* For info only */
nr_pfns = 0;
- if ( !read_exact(io_fd, &p2m_size, sizeof(unsigned long)) )
+ if ( read_exact(io_fd, &p2m_size, sizeof(unsigned long)) )
{
ERROR("read: p2m_size");
goto out;
prev_pc = this_pc;
}
- if ( !read_exact(io_fd, &j, sizeof(int)) )
+ if ( read_exact(io_fd, &j, sizeof(int)) )
{
ERROR("Error when reading batch size");
goto out;
if ( j == -2 )
{
new_ctxt_format = 1;
- if ( !read_exact(io_fd, &max_vcpu_id, sizeof(int)) ||
+ if ( read_exact(io_fd, &max_vcpu_id, sizeof(int)) ||
(max_vcpu_id >= 64) ||
- !read_exact(io_fd, &vcpumap, sizeof(uint64_t)) )
+ read_exact(io_fd, &vcpumap, sizeof(uint64_t)) )
{
ERROR("Error when reading max_vcpu_id");
goto out;
goto out;
}
- if ( !read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long)) )
+ if ( read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long)) )
{
ERROR("Error when reading region pfn types");
goto out;
/* In verify mode, we use a copy; otherwise we work in place */
page = verify ? (void *)buf : (region_base + i*PAGE_SIZE);
- if ( !read_exact(io_fd, page, PAGE_SIZE) )
+ if ( read_exact(io_fd, page, PAGE_SIZE) )
{
ERROR("Error when reading page (type was %lx)", pagetype);
goto out;
uint32_t rec_len;
/* Set HVM-specific parameters */
- if ( !read_exact(io_fd, magic_pfns, sizeof(magic_pfns)) )
+ if ( read_exact(io_fd, magic_pfns, sizeof(magic_pfns)) )
{
ERROR("error reading magic page addresses");
goto out;
*store_mfn = magic_pfns[2];
/* Read HVM context */
- if ( !read_exact(io_fd, &rec_len, sizeof(uint32_t)) )
+ if ( read_exact(io_fd, &rec_len, sizeof(uint32_t)) )
{
ERROR("error read hvm context size!\n");
goto out;
goto out;
}
- if ( !read_exact(io_fd, hvm_buf, rec_len) )
+ if ( read_exact(io_fd, hvm_buf, rec_len) )
{
ERROR("error loading the HVM context");
goto out;
unsigned long *pfntab;
int nr_frees;
- if ( !read_exact(io_fd, &count, sizeof(count)) ||
+ if ( read_exact(io_fd, &count, sizeof(count)) ||
(count > (1U << 28)) ) /* up to 1TB of address space */
{
ERROR("Error when reading pfn count (= %u)", count);
goto out;
}
- if ( !read_exact(io_fd, pfntab, sizeof(unsigned long)*count) )
+ if ( read_exact(io_fd, pfntab, sizeof(unsigned long)*count) )
{
ERROR("Error when reading pfntab");
goto out;
if ( !(vcpumap & (1ULL << i)) )
continue;
- if ( !read_exact(io_fd, &ctxt, ((guest_width == 8)
- ? sizeof(ctxt.x64)
- : sizeof(ctxt.x32))) )
+ if ( read_exact(io_fd, &ctxt, ((guest_width == 8)
+ ? sizeof(ctxt.x64)
+ : sizeof(ctxt.x32))) )
{
ERROR("Error when reading ctxt %d", i);
goto out;
if ( !ext_vcpucontext )
continue;
- if ( !read_exact(io_fd, &domctl.u.ext_vcpucontext, 128) ||
+ if ( read_exact(io_fd, &domctl.u.ext_vcpucontext, 128) ||
(domctl.u.ext_vcpucontext.vcpu != i) )
{
ERROR("Error when reading extended ctxt %d", i);
}
}
- if ( !read_exact(io_fd, shared_info_page, PAGE_SIZE) )
+ if ( read_exact(io_fd, shared_info_page, PAGE_SIZE) )
{
ERROR("Error when reading shared info page");
goto out;
static int noncached_write(int fd, int live, void *buffer, int len)
{
static int write_count = 0;
-
- int rc = write(fd,buffer,len);
+ int rc = (write_exact(fd, buffer, len) == 0) ? len : -1;
write_count += len;
if ( write_count >= (MAX_PAGECACHE_USAGE * PAGE_SIZE) )
#endif
-static inline ssize_t write_exact(int fd, void *buf, size_t count)
-{
- return (write(fd, buf, count) == count);
-}
-
static int print_stats(int xc_handle, uint32_t domid, int pages_sent,
xc_shadow_op_stats_t *stats, int print)
{
: sizeof(ctxt.x32));
uint32_t chunk2_sz = 0;
uint32_t tot_sz = (chunk1_sz + 8) + (chunk2_sz + 8);
- if ( !write_exact(io_fd, &signature, sizeof(signature)) ||
- !write_exact(io_fd, &tot_sz, sizeof(tot_sz)) ||
- !write_exact(io_fd, "vcpu", 4) ||
- !write_exact(io_fd, &chunk1_sz, sizeof(chunk1_sz)) ||
- !write_exact(io_fd, &ctxt, chunk1_sz) ||
- !write_exact(io_fd, "extv", 4) ||
- !write_exact(io_fd, &chunk2_sz, sizeof(chunk2_sz)) )
+ if ( write_exact(io_fd, &signature, sizeof(signature)) ||
+ write_exact(io_fd, &tot_sz, sizeof(tot_sz)) ||
+ write_exact(io_fd, "vcpu", 4) ||
+ write_exact(io_fd, &chunk1_sz, sizeof(chunk1_sz)) ||
+ write_exact(io_fd, &ctxt, chunk1_sz) ||
+ write_exact(io_fd, "extv", 4) ||
+ write_exact(io_fd, &chunk2_sz, sizeof(chunk2_sz)) )
{
ERROR("write: extended info");
goto out;
}
}
- if ( !write_exact(io_fd, p2m_frame_list,
- P2M_FL_ENTRIES * sizeof(xen_pfn_t)) )
+ if ( write_exact(io_fd, p2m_frame_list,
+ P2M_FL_ENTRIES * sizeof(xen_pfn_t)) )
{
ERROR("write: p2m_frame_list");
goto out;
}
/* Start writing out the saved-domain record. */
- if ( !write_exact(io_fd, &p2m_size, sizeof(unsigned long)) )
+ if ( write_exact(io_fd, &p2m_size, sizeof(unsigned long)) )
{
ERROR("write: p2m_size");
goto out;
}
}
- if ( !write_exact(io_fd, &batch, sizeof(unsigned int)) )
+ if ( write_exact(io_fd, &batch, sizeof(unsigned int)) )
{
ERROR("Error when writing to state file (2) (errno %d)",
errno);
goto out;
}
- if ( !write_exact(io_fd, pfn_type, sizeof(unsigned long)*batch) )
+ if ( write_exact(io_fd, pfn_type, sizeof(unsigned long)*batch) )
{
ERROR("Error when writing to state file (3) (errno %d)",
errno);
DPRINTF("Entering debug resend-all mode\n");
/* send "-1" to put receiver into debug mode */
- if ( !write_exact(io_fd, &minusone, sizeof(int)) )
+ if ( write_exact(io_fd, &minusone, sizeof(int)) )
{
ERROR("Error when writing to state file (6) (errno %d)",
errno);
}
chunk.vcpumap = vcpumap;
- if ( !write_exact(io_fd, &chunk, sizeof(chunk)) )
+ if ( write_exact(io_fd, &chunk, sizeof(chunk)) )
{
ERROR("Error when writing to state file (errno %d)", errno);
goto out;
/* Zero terminate */
i = 0;
- if ( !write_exact(io_fd, &i, sizeof(int)) )
+ if ( write_exact(io_fd, &i, sizeof(int)) )
{
ERROR("Error when writing to state file (6') (errno %d)", errno);
goto out;
(unsigned long *)&magic_pfns[1]);
xc_get_hvm_param(xc_handle, dom, HVM_PARAM_STORE_PFN,
(unsigned long *)&magic_pfns[2]);
- if ( !write_exact(io_fd, magic_pfns, sizeof(magic_pfns)) )
+ if ( write_exact(io_fd, magic_pfns, sizeof(magic_pfns)) )
{
ERROR("Error when writing to state file (7)");
goto out;
goto out;
}
- if ( !write_exact(io_fd, &rec_size, sizeof(uint32_t)) )
+ if ( write_exact(io_fd, &rec_size, sizeof(uint32_t)) )
{
ERROR("error write hvm buffer size");
goto out;
}
- if ( !write_exact(io_fd, hvm_buf, rec_size) )
+ if ( write_exact(io_fd, hvm_buf, rec_size) )
{
ERROR("write HVM info failed!\n");
goto out;
j++;
}
- if ( !write_exact(io_fd, &j, sizeof(unsigned int)) )
+ if ( write_exact(io_fd, &j, sizeof(unsigned int)) )
{
ERROR("Error when writing to state file (6a) (errno %d)", errno);
goto out;
i++;
if ( (j == 1024) || (i == p2m_size) )
{
- if ( !write_exact(io_fd, &pfntab, sizeof(unsigned long)*j) )
+ if ( write_exact(io_fd, &pfntab, sizeof(unsigned long)*j) )
{
ERROR("Error when writing to state file (6b) (errno %d)",
errno);
mfn_to_pfn(xen_cr3_to_pfn(ctxt.x64.ctrlreg[1])));
}
- if ( !write_exact(io_fd, &ctxt, ((guest_width==8)
- ? sizeof(ctxt.x64)
- : sizeof(ctxt.x32))) )
+ if ( write_exact(io_fd, &ctxt, ((guest_width==8)
+ ? sizeof(ctxt.x64)
+ : sizeof(ctxt.x32))) )
{
ERROR("Error when writing to state file (1) (errno %d)", errno);
goto out;
ERROR("No extended context for VCPU%d", i);
goto out;
}
- if ( !write_exact(io_fd, &domctl.u.ext_vcpucontext, 128) )
+ if ( write_exact(io_fd, &domctl.u.ext_vcpucontext, 128) )
{
ERROR("Error when writing to state file (2) (errno %d)", errno);
goto out;
memcpy(page, live_shinfo, PAGE_SIZE);
SET_FIELD(((shared_info_either_t *)page),
arch.pfn_to_mfn_frame_list_list, 0);
- if ( !write_exact(io_fd, page, PAGE_SIZE) )
+ if ( write_exact(io_fd, page, PAGE_SIZE) )
{
ERROR("Error when writing to state file (1) (errno %d)", errno);
goto out;
return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
}
-static int dorw(int fd, char *data, size_t size, int do_write)
-{
- size_t offset = 0;
- ssize_t len;
-
- while ( offset < size )
- {
- if (do_write)
- len = write(fd, data + offset, size - offset);
- else
- len = read(fd, data + offset, size - offset);
-
- if ( len == -1 )
- {
- if ( errno == EINTR )
- continue;
- return -1;
- }
-
- offset += len;
- }
-
- return 0;
-}
-
evtchn_port_or_error_t
xc_evtchn_pending(int xce_handle)
{
evtchn_port_t port;
- if ( dorw(xce_handle, (char *)&port, sizeof(port), 0) == -1 )
+ if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
return -1;
return port;
int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
{
- return dorw(xce_handle, (char *)&port, sizeof(port), 1);
+ return write_exact(xce_handle, (char *)&port, sizeof(port));
}
/* Optionally flush file to disk and discard page cache */
return bind.port;
}
-static int dorw(int fd, char *data, size_t size, int do_write)
-{
- size_t offset = 0;
- ssize_t len;
-
- while ( offset < size )
- {
- if (do_write)
- len = write(fd, data + offset, size - offset);
- else
- len = read(fd, data + offset, size - offset);
-
- if ( len == -1 )
- {
- if ( errno == EINTR )
- continue;
- return -1;
- }
-
- offset += len;
- }
-
- return 0;
-}
-
evtchn_port_or_error_t
xc_evtchn_pending(int xce_handle)
{
evtchn_port_t port;
- if ( dorw(xce_handle, (char *)&port, sizeof(port), 0) == -1 )
+ if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
return -1;
return port;
int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
{
- return dorw(xce_handle, (char *)&port, sizeof(port), 1);
+ return write_exact(xce_handle, (char *)&port, sizeof(port));
}
/* Optionally flush file to disk and discard page cache */
}
}
+int read_exact(int fd, void *data, size_t size)
+{
+ size_t offset = 0;
+ ssize_t len;
+
+ while ( offset < size )
+ {
+ len = read(fd, (char *)data + offset, size - offset);
+ if ( (len == -1) && (errno == EINTR) )
+ continue;
+ if ( len <= 0 )
+ return -1;
+ offset += len;
+ }
+
+ return 0;
+}
+
+int write_exact(int fd, const void *data, size_t size)
+{
+ size_t offset = 0;
+ ssize_t len;
+
+ while ( offset < size )
+ {
+ len = write(fd, (const char *)data + offset, size - offset);
+ if ( (len == -1) && (errno == EINTR) )
+ continue;
+ if ( len <= 0 )
+ return -1;
+ offset += len;
+ }
+
+ return 0;
+}
+
/*
* Local variables:
* mode: C
unsigned long long ptr, unsigned long long val);
int xc_flush_mmu_updates(int xc_handle, struct xc_mmu *mmu);
+/* Return 0 on success; -1 on error. */
+int read_exact(int fd, void *data, size_t size);
+int write_exact(int fd, const void *data, size_t size);
+
#endif /* __XC_PRIVATE_H__ */
return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
}
-static int dorw(int fd, char *data, size_t size, int do_write)
-{
- size_t offset = 0;
- ssize_t len;
-
- while ( offset < size )
- {
- if (do_write)
- len = write(fd, data + offset, size - offset);
- else
- len = read(fd, data + offset, size - offset);
-
- if ( len == -1 )
- {
- if ( errno == EINTR )
- continue;
- return -1;
- }
-
- offset += len;
- }
-
- return 0;
-}
-
evtchn_port_or_error_t
xc_evtchn_pending(int xce_handle)
{
evtchn_port_t port;
- if ( dorw(xce_handle, (char *)&port, sizeof(port), 0) == -1 )
+ if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
return -1;
return port;
int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
{
- return dorw(xce_handle, (char *)&port, sizeof(port), 1);
+ return write_exact(xce_handle, (char *)&port, sizeof(port));
}
/* Optionally flush file to disk and discard page cache */